package guoanmaker.provider.business.controller;


import java.io.InputStream;
import java.util.List;

import io.swagger.annotations.ApiOperation;
import guoanmaker.provider.business.model.PersonalPlatform;
import guoanmaker.provider.business.service.PersonalPlatformSeriveinterface;
import guoanmaker.provider.helper.common.AjaxJson;
import guoanmaker.provider.helper.common.abstractobj.ApiController;
import guoanmaker.provider.helper.common.util.OSSUnitHelper;

import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.aliyun.oss.OSSClient;


@RestController
@RequestMapping(ApiController.COMMODITY_URL)
public class PersonalPlatformController {
	
	
	@Autowired
	private PersonalPlatformSeriveinterface   personalPlatformSerive;
	
	@ApiOperation(value="录入平台上线邀约", notes="录入平台上线邀约")
	@PostMapping("/insertPersonalPlatform")
	public AjaxJson insertPersonalPlatform(@RequestParam MultipartFile dataFile){
		AjaxJson ajaxJson=new AjaxJson();
		try (InputStream in = dataFile.getInputStream(); Workbook wb = WorkbookFactory.create(in);) {
		     personalPlatformSerive.insertPersonalPlatform(wb);
		     ajaxJson.setSuccess(true).setStatus(200).setData("录入成功");
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("录入失败");
		}
		return ajaxJson;
	}

	
	@ApiOperation(value="分页查询录入平台信息" ,notes="分页查询录入平台信息")
	@PostMapping("/selectPersonalPlatform")
	public AjaxJson selectPersonalPlatform(@RequestParam(value = "page", defaultValue = "0") Integer page,
            @RequestParam(value = "size", defaultValue = "10") Integer size){
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(personalPlatformSerive.selectAllPersonalPlatform(page,size));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		return ajaxJson;
		
	}
	
	
	
	@ApiOperation(value="根据id查询平台信息",notes="根据id查询平台信息")
	@PostMapping("/selectOnePersonalPlatform")
	public AjaxJson selectOnePersonalPlatform(@RequestParam(value="id") String id){
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(personalPlatformSerive.selectOnePersonalPlatform(id));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		return ajaxJson;
		
		
	}
	
	@ApiOperation(value="查询全部" ,notes="查询全部")
	@PostMapping("/selectAllPersonalPlatform")
	public AjaxJson selectAllPersonalPlatform(){
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(personalPlatformSerive.selectPersonalPlatform());
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		return ajaxJson;
		
	}
	
	@ApiOperation(value="新增/修改平台信息" ,notes="新增/修改平台信息")
	@PostMapping("/addorUpdatePersonalPlatform")
	public AjaxJson  addorUpdatePersonalPlatform(@RequestBody PersonalPlatform personalPlatform){
		AjaxJson ajaxJson=new AjaxJson();
		ajaxJson.setSuccess(true).setStatus(200).setData(personalPlatformSerive.addorUpdatePersonalPlatform(personalPlatform));
		return	ajaxJson;
	}
	
	@ApiOperation(value="删除平台信息" ,notes="删除平台信息")
	@PostMapping("/deletePersonalPlatform")
	public AjaxJson deletePersonalPlatform(String id){
		AjaxJson ajaxJson=new AjaxJson();
		try {
			personalPlatformSerive.deletePersonalPlatform(id);
			ajaxJson.setSuccess(true).setStatus(200).setData("删除成功");
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("删除失败");
		}
		return ajaxJson;
	}
}
